<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var articleDataGrid;
    var articleTree;

    $(function() {
        articleTree = $('#articleTree').tree({
        	lines:true,
            url : '${path }/app/article/catalog/tree',
            parentField : 'pid',
            lines : true,
            onClick : function(node) {
            	$(this).tree('toggle', node.target);
            	$('#catalogId').val(node.id);
            	$(".article").layout('panel','center').panel('setTitle','当前栏目：'+node.text+" 》 信息列表");
                articleDataGrid.datagrid('load', {
                    catalogId: node.id
                });
            }
        });

        articleDataGrid = $('#articleDataGrid').datagrid({
            url : '${path }/app/article/dataGrid',
            fit : true,
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'sequence',
	        sortOrder : 'asc',
            pageSize : 10,
            pageList : [ 10, 20, 30, 40, 50 ],
            columns : [ [ {
                width : '280',
                title : '文章标题',
                field : 'title',
                sortable : true
            }, {
                width : '380',
                title : '摘要',
                field : 'summary',
                sortable : true
            },{
                width : '50',
                title : '头条',
                field : 'headlineNews',
                sortable : true
            },{
                width : '50',
                title : '焦点',
                field : 'isFocus',
                sortable : true
            },{
                width : '50',
                title : '排序',
                field : 'sequence'
            },{
                width : '60',
                title : '状态',
                field : 'status',
                sortable : true,
                formatter : function(value, row, index) {
                    switch (value) {
                    case '0':
                        return '停用';
                    case '1':
                        return '正常';
                    }
                }
            }, {
                field : 'action',
                title : '操作',
                width : 130,
                formatter : function(value, row, index) {
                    var str = '';
                        <shiro:hasPermission name="/app/article/edit">
                            str += $.formatString('<a href="javascript:void(0)" class="article-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="editArticleFun(\'{0}\');" >编辑</a>', row.id);
                        </shiro:hasPermission>
                        <shiro:hasPermission name="/app/article/delete">
                            str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                            str += $.formatString('<a href="javascript:void(0)" class="article-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="deleteArticleFun(\'{0}\');" >删除</a>', row.id);
                        </shiro:hasPermission>
                    return str;
                }
            }] ],
            onLoadSuccess:function(data){
                $('.article-easyui-linkbutton-edit').linkbutton({text:'编辑'});
                $('.article-easyui-linkbutton-del').linkbutton({text:'删除'});
            },
            toolbar : '#articleToolbar'
        });
    });
      //获取父id
    function getParentId(){
    	var parentId=$("#parentid").val();
    	return parentId;
    }  
    function addArticleFun() {
    	var id="";
    	if ($('#catalogId').val()=='0' || $('#catalogId').val()==""){
        	 $.messager.alert('提示', "请选择文章栏目！", 'info');
        	return;
   		}
    	parent.addFrameTab('文章编辑','${path }/app/article/add?catalogId='+$("#catalogId").val(),'');
    }
    
    function deleteArticleFun(id) {
     if (id == undefined) {
        	var rows = articleDataGrid.datagrid('getSelections');
        	id = rows[0].id;
        } else {
            articleDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.messager.confirm('询问', '您是否要删除当前信息？', function(b) {
            if (b) {
                progressLoad();
                $.post('${path }/app/article/delete', {
                    id : id
                }, function(result) {
                    if (result.success) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        articleDataGrid.datagrid('reload');
                        $("#articleTree").tree("reload");
                    } else {
                        parent.$.messager.alert('错误', result.msg, 'error');
                    }
                    progressClose();
                }, 'JSON');
            }
        });
    }
    
    function editArticleFun(id) {
        if (id == undefined) {
            var rows = articleDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
            articleDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.addFrameTab('文章编辑','${path }/app/article/edit?id='+id,'');
    }
    
    function searchArticleFun() {
        articleDataGrid.datagrid('load', $.serializeObject($('#searchArticleForm')));
    }
    function cleanArticleFun() {
        $('#searchArticleForm input').val('');
        articleDataGrid.datagrid('load', {});
    }
</script>
<div class="easyui-layout article" data-options="fit:true,border:false">
 <div data-options="region:'north',border:false" style="height: 30px; overflow: hidden;background-color: #fff">
        <form id="searchArticleForm">
       		<input name="catalogId" type="hidden" id="catalogId" value=""/>
            <table>
                <tr>
                    <th>标题:</th>
                    <td><input name="title" placeholder="请输入文章标题"/></td>
                    <th>创建人:</th>
                    <td><input name="username" placeholder="请输入创建人"/></td>
                    <th>创建时间:</th>
                    <td>
                        <input name="createdateStart" placeholder="点击选择时间" onclick="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" readonly="readonly" />至
                        <input  name="createdateEnd" placeholder="点击选择时间" onclick="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" readonly="readonly" />
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="searchArticleFun();">查询</a>
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-x-circle',plain:true" onclick="cleanArticleFun();">清空</a>
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <div data-options="region:'center',border:true,title:'信息列表'" >
        <table id="articleDataGrid" data-options="fit:true,border:false"></table>
    </div>
    <div data-options="region:'west',border:true,split:false,hide:true,title:'文章栏目'" refresh="reloadAll" expand="expandAll" collapse="collapseAll" style="width:150px; ">
        <ul id="articleTree" fit="true" style="width:160px;margin: 10px 10px 10px 10px"></ul>
    </div>
</div>
<div id="articleToolbar" style="display: none;">
    <shiro:hasPermission name="/app/article/add">
        <a onclick="addArticleFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-plus icon-green'">添加</a>
    </shiro:hasPermission>
</div>